package com.jaya.budan.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.jaya.budan.R;
import com.jaya.budan.bean.ListUser_Information;
import com.jaya.budan.bean.User_Wallet;

import java.util.List;

public class GV_GeRen_Update_Cover_Adapter extends BaseAdapter {

    private Context mcontext;
    private List<ListUser_Information> users;
    private int select = -1;
    public GV_GeRen_Update_Cover_Adapter(Context context, List<ListUser_Information> user_informations){
        mcontext = context;
        users = user_informations;
    }

    public int getSelect() {
        return select;
    }

    public void setSelect(int select) {
        this.select = select;
    }

    @Override
    public int getCount() {
        return users.size();
    }

    @Override
    public Object getItem(int position) {
        return users.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint({"ViewHolder", "SetTextI18n"})
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = View.inflate(mcontext, R.layout.gv_geren_update_cover_item, null);
        Button btn_update_cover = convertView.findViewById(R.id.btn_update_cover);
        TextView tv_update_cover_name = convertView.findViewById(R.id.tv_update_cover_name);
        ImageView iv_photo_album_icon = convertView.findViewById(R.id.iv_photo_album_icon);
        ImageView iv_update_cover_isvip = convertView.findViewById(R.id.iv_update_cover_isvip);
        tv_update_cover_name.setText(users.get(position).getName() + "");
        Glide.with(mcontext).load(users.get(position).getThumb_path() + "").apply(new RequestOptions()
                .placeholder(R.mipmap.banner).error(R.mipmap.banner)
                .diskCacheStrategy(DiskCacheStrategy.NONE)//关闭Glide的硬盘缓存机制
        ).into(iv_photo_album_icon);
        if (users.get(position).getIs_vip().equals("1")){
            iv_update_cover_isvip.setVisibility(View.VISIBLE);
        } else {
            iv_update_cover_isvip.setVisibility(View.GONE);
        }
        if (users.get(position).getIs_use() == 1){
            btn_update_cover.setText("正在使用");
            btn_update_cover.setBackgroundResource(R.drawable.login_login);
        } else {
            btn_update_cover.setText("选择");
            btn_update_cover.setBackgroundResource(R.drawable.login_exit);
        }
        btn_update_cover.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (position == select){
                    btn_update_cover.setText("使用中");
                    btn_update_cover.setBackgroundResource(R.drawable.login_login);
                } else {
                    btn_update_cover.setText("选择");
                    btn_update_cover.setBackgroundResource(R.drawable.login_exit);
                }
            }
        });
        return convertView;
    }
}